package jjn.effective_java.chapter6.item34;

/**
 * Enum with data and behaviour.
 *
 * @author Jiang Jining
 * @since 2023-04-26 19:56
 */
public enum Planet {
    MERCURY(3.302e23, 2.439e6, "Mercury"),
    VENUS(4.86e24, 6.052e6, "Venus"),
    EARTH(5.975e24, 6.378e6, "Earth"),
    MARS(6.419e23, 3.393e6, "Mars"),
    JUPITER(1.899e27, 7.149e7, "Jupiter"),
    SATURN(5.685e26, 6.027e7, "Saturn"),
    URANUS(8.683e25, 2.556e7, "Uranus"),
    NEPTUNE(1.024e26, 2.477e7, "Neptune");
    private final double mass;
    private final double radius;
    private final String name;
    private final double surfaceGravity;
    
    private static final double G = 6.67300E-11;
    
    Planet(final double mass, final double radius, String name) {
        this.mass = mass;
        this.radius = radius;
        this.name = name;
        this.surfaceGravity = G * mass / (radius * radius);
    }
    
    public double getMass() {
        return mass;
    }
    
    public double getRadius() {
        return radius;
    }
    
    public double surfaceWeight(double mass) {
        return mass * surfaceGravity;
    }
    
    public double surfaceGravity() {
        return surfaceGravity;
    }
    
    @Override
    public String toString() {
        return "Planet{" + "mass=" + mass +
                ", radius=" + radius +
                ", name='" + name + '\'' +
                ", surfaceGravity=" + surfaceGravity +
                '}';
    }
}
